package com.vc.mobile.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.vc.service.RemoteService;

@Controller
@RequestMapping("/mobile")
public class MobileController {
	
	@Autowired
	private RemoteService remoteService;

	@RequestMapping("/{code}/{marketId}/buy")
	public String buyOrders(ModelMap model, 
			@PathVariable String code,
			@PathVariable String marketId) {
		model.addAttribute("code", code);
		model.addAttribute("marketId", marketId);
		model.addAttribute("buys", remoteService.findBuyOrders(code, marketId));
		return "mobile/buy";
	}
	
	@RequestMapping("/{code}/{marketId}/chart")
	public String tradeChart(ModelMap model, 
			@PathVariable String code,
			@PathVariable String marketId) {
		String[] codes = code.split("_");
		model.addAttribute("code", codes[0]);
		model.addAttribute("secondCode", codes[1]);
		model.addAttribute("marketId", marketId);
		model.addAttribute("btcPrice", remoteService.findBtcPrice());
		model.addAttribute("ltcPrice", remoteService.findLtcPrice());
		return "mobile/chart";
	}
	
	@RequestMapping("/{code}/{marketId}/sell")
	public String sellOrders(ModelMap model, 
			@PathVariable String code,
			@PathVariable String marketId) {
		model.addAttribute("code", code);
		model.addAttribute("marketId", marketId);
		model.addAttribute("sells", remoteService.findSellOrders(code, marketId));
		return "mobile/sell";
	}
	
	@RequestMapping("/{code}/{marketId}/his")
	public String hisOrders(ModelMap model, 
			@PathVariable String code,
			@PathVariable String marketId) {
		model.addAttribute("code", code);
		model.addAttribute("marketId", marketId);
		model.addAttribute("hisTrades", remoteService.findHistoryOrders(code, marketId));
		return "mobile/his";
	}
	
	@RequestMapping("/{code}/{marketId}/detail")
	public String detail(ModelMap model, 
			@PathVariable String code,
			@PathVariable String marketId) {
		String[] codes = code.split("_");
		model.addAttribute("code", codes[0]);
		model.addAttribute("secondCode", codes[1]);
		model.addAttribute("marketId", marketId);
		model.addAttribute("btcPrice", remoteService.findBtcPrice());
		model.addAttribute("market", remoteService.findMarketById(marketId));
		return "mobile/detail";
	}
	
	@RequestMapping("/index")
	public String index(ModelMap model) {
		model.addAttribute("btcPrice", remoteService.findBtcPrice());
		model.addAttribute("markets", remoteService.findAllMarkets());
		return "mobile/index";
	}
}
